package com.zyx.strategy.stg04;

import com.zyx.strategy.stg02.SpringContextHolder;
import org.springframework.util.StringUtils;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * <p>策略枚举类
 *
 * @author Yaxi.Zhang
 * @since 2022/10/10 00:50
 */
public enum FourthHandlerEnum {

    Handler1("Handler1") {
        @Override
        public void handle() {
            FourthHandler bean = SpringContextHolder.getBean(FourthHandler.class);
            bean.handler();
        }
    },
    Handler2("Handler2") {
        @Override
        public void handle() {
            System.out.println("Handler2执行");
        }
    },
    Handler3("Handler3") {
        @Override
        public void handle() {
            System.out.println("Handler3执行");
        }
    };

    private final String type;

    public abstract void handle();

    FourthHandlerEnum(String type) {
        this.type = type;
    }

    public String getType() {
        return type;
    }

    public static FourthHandlerEnum getByType(String type) {
        return Stream.of(values()).filter(it -> Objects.equals(it.getType(), type)).findFirst().orElse(null);
    }


}
